package com.example.ruralservicedigitalplatform.service.impl;

import com.example.ruralservicedigitalplatform.domain.po.DeliveryMan;
import com.example.ruralservicedigitalplatform.domain.query.PageBean;
import com.example.ruralservicedigitalplatform.mapper.DeliveryManMapper;
import com.example.ruralservicedigitalplatform.service.DeliveryManService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeliveryManServiceImpl implements DeliveryManService {
    @Autowired
    private DeliveryManMapper deliveryManMapper;

    //根据用户名查询配送员
    @Override
    public DeliveryMan getByName(String username) {
        return deliveryManMapper.getByName(username);
    }

    //分页查询
    @Override
    public PageBean page(Integer page, Integer pageSize, Integer deliverymanId, String name, String password, String gender, int phoneNumber, int age, String image, String idNumber, int status, double averageTime, BigDecimal totalDeliveries, BigDecimal rating, LocalDate begin, LocalDate end) {
        //1.设置分页参数
        PageHelper.startPage(page,pageSize);
        //2.执行查询
        List<DeliveryMan> accountList = deliveryManMapper.list2(deliverymanId,name,password,gender,phoneNumber,age,image,idNumber,status,  averageTime,  totalDeliveries, rating,begin, end);
        Page<DeliveryMan> p=(Page<DeliveryMan>)accountList;
        //3.封装PageBean对象
        return new PageBean(p.getTotal(),p.getResult());
    }

//更新配送员信息
    @Override
    public void update(DeliveryMan deliveryMan) {
        deliveryMan.setUpdateTime(LocalDateTime.now());
        deliveryManMapper.update(deliveryMan);
    }

    @Override
    public void delete(List<Integer> ids) {
        deliveryManMapper.delete(ids);
    }

    @Override
    public void add(DeliveryMan deliveryMan) {
        deliveryMan.setUpdateTime(LocalDateTime.now());
        deliveryManMapper.insert(deliveryMan);
    }

}
